<html>
<head>
    <meta charset="utf-8"/>
<meta name="description" content=""/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>

<title>JSTL标签+EL表达式改进360影视采集练习案例 | 絷缘的博客</title>

<link rel="shortcut icon" href="https://zydnc.gitee.io/favicon.ico?v=1732378515642">

<link href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://zydnc.gitee.io/styles/main.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/css/bootstrap.min.css">

<script src="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets/highlight.min.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.15.10/languages/dockerfile.min.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.15.10/languages/dart.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/moment@2.27.0/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.min.js"></script>
<!-- DEMO JS -->
<!--<script src="media/scripts/index.js"></script>-->



    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.css">
 <script src='//unpkg.com/valine/dist/Valine.min.js'></script>
</head>
<body>
<div class="main gt-bg-theme-color-first">
    <nav class="navbar navbar-expand-lg">
    <div class="navbar-brand">
        <img class="user-avatar" src="/images/avatar.png" alt="头像">
        <div class="site-name gt-c-content-color-first">
            絷缘的博客
        </div>
    </div>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <i class="fas fa-bars gt-c-content-color-first" style="font-size: 18px"></i>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <div class="navbar-nav mr-auto" style="text-align: center">
            
                <div class="nav-item">
                    
                        <a href="/" class="menu gt-a-link">
                            首页
                        </a>
                    
                </div>
            
                <div class="nav-item">
                    
                        <a href="/archives" class="menu gt-a-link">
                            归档
                        </a>
                    
                </div>
            
                <div class="nav-item">
                    
                        <a href="/tags" class="menu gt-a-link">
                            标签
                        </a>
                    
                </div>
            
                <div class="nav-item">
                    
                        <a href="/about" class="menu gt-a-link">
                            关于
                        </a>
                    
                </div>
            
                <div class="nav-item">
                    
                        <a href="/friends" class="menu gt-a-link">
                            友链
                        </a>
                    
                </div>
            
        </div>
        <div style="text-align: center">
            <form id="gridea-search-form" style="position: relative" data-update="1732378515642" action="/search/index.html">
                <input class="search-input" autocomplete="off" spellcheck="false" name="q" placeholder="搜索文章" />
                <i class="fas fa-search gt-c-content-color-first" style="position: absolute; top: 9px; left: 10px;"></i>
            </form>
        </div>
    </div>
</nav>

    <div class="post-container">
        <div class="post-detail gt-bg-theme-color-second">
            <article class="gt-post-content">
                <h2 class="post-title">
                    JSTL标签+EL表达式改进360影视采集练习案例
                </h2>
                <div class="post-info">
                    <time class="post-time gt-c-content-color-first">
                        · 2021-01-30 ·
                    </time>
                    
                        <a href="https://zydnc.gitee.io/NhmdSaNuN/" class="post-tags">
                            # 练习
                        </a>
                    
                        <a href="https://zydnc.gitee.io/oPMSWE43i/" class="post-tags">
                            # 360影视
                        </a>
                    
                </div>
                <div class="post-content">
                    <h2 id="一-导入jstl标签库和el表达式的依赖">一、导入JSTL标签库和EL表达式的依赖</h2>
<pre><code class="language-xml">&lt;dependency&gt;
    &lt;groupId&gt;javax.servlet.jsp.jstl&lt;/groupId&gt;
    &lt;artifactId&gt;jstl&lt;/artifactId&gt;
    &lt;version&gt;1.2&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;javax.el&lt;/groupId&gt;
    &lt;artifactId&gt;javax.el-api&lt;/artifactId&gt;
    &lt;version&gt;3.0.0&lt;/version&gt;
&lt;/dependency&gt;
</code></pre>
<blockquote>
<p>如果你们创建的不是maven项目，那么可能需要自己去tomcat的lib目录下去找这两个JAR包，然后导入到项目中</p>
</blockquote>
<h2 id="二-改进之前的jsp页面">二、改进之前的JSP页面</h2>
<pre><code class="language-html">&lt;%@ page import=&quot;com.zhiyuan.utils.HttpUtils&quot; %&gt;
&lt;%@ page import=&quot;com.google.gson.JsonArray&quot; %&gt;
&lt;%@ page import=&quot;com.google.gson.JsonParser&quot; %&gt;
&lt;%@ page import=&quot;com.zhiyuan.bean.FilmInfo&quot; %&gt;
&lt;%@ page import=&quot;java.util.ArrayList&quot; %&gt;
&lt;%@ page import=&quot;com.google.gson.Gson&quot; %&gt;
&lt;%@ page import=&quot;com.google.gson.JsonElement&quot; %&gt;
&lt;%@ page contentType=&quot;text/html;charset=UTF-8&quot; language=&quot;java&quot; pageEncoding=&quot;UTF-8&quot; isELIgnored=&quot;false&quot; %&gt;
&lt;%@ taglib prefix=&quot;c&quot; uri=&quot;http://java.sun.com/jsp/jstl/core&quot; %&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot;&gt;
    &lt;title&gt;360Video&lt;/title&gt;
    &lt;link rel=&quot;icon&quot; href=&quot;https://www.360kan.com/favicon.ico&quot;&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;./css/style.css?v=&lt;%=Math.random()%&gt;&quot;&gt;
    &lt;script src=&quot;./js/jquery-3.1.1.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;header&quot;&gt;
    &lt;div class=&quot;nav&quot;&gt;360影视采集&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;container&quot;&gt;
    &lt;ul class=&quot;list&quot;&gt;
    &lt;%
        String data = HttpUtils.getData(&quot;https://www.360kan.com/dianying/list.php?rank=rankhot&amp;cat=all&amp;area=all&amp;act=all&amp;year=all&amp;pageno=2&amp;from=dianying_list&quot;);
        JsonArray jsonElements = new JsonParser().parse(data).getAsJsonArray();
        ArrayList&lt;FilmInfo&gt; filmInfos = new ArrayList&lt;&gt;();
        Gson gson = new Gson();
        for (JsonElement filmInfo : jsonElements) {
            filmInfos.add(gson.fromJson(filmInfo,FilmInfo.class));
        }
        request.setAttribute(&quot;data&quot;,filmInfos);
    %&gt;
        &lt;c:forEach items=&quot;${requestScope.data}&quot; var=&quot;film&quot;&gt;
            &lt;li&gt;
                &lt;div class=&quot;poster&quot;&gt;
                    &lt;img src=&quot;${film.poster}&quot;&gt;
                    &lt;c:if test=&quot;${'付费'.equals(film.paid)}&quot;&gt;
                        &lt;div class=&quot;paid&quot;&gt;付费&lt;/div&gt;
                    &lt;/c:if&gt;
                    &lt;div class=&quot;info&quot;&gt;
                        &lt;div class=&quot;year&quot;&gt;${film.year}&lt;/div&gt;
                        &lt;c:if test=&quot;${film.score!=null}&quot;&gt;
                            &lt;div class=&quot;score&quot;&gt;${film.score}&lt;/div&gt;
                        &lt;/c:if&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class=&quot;detail&quot;&gt;
                    &lt;div class=&quot;name&quot;&gt;${film.name}&lt;/div&gt;
                    &lt;div class=&quot;star&quot;&gt;${film.star.length()&gt;12?film.star.substring(0,12).concat(&quot;...&quot;):film.star}&lt;/div&gt;
                &lt;/div&gt;
            &lt;/li&gt;
        &lt;/c:forEach&gt;
    &lt;/ul&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<blockquote>
<p>注意：在页面中若想使用JSTL标签，必须要引入JSTL标签库，EL表达式不需要引入，可以直接使用<br>
&lt;%@ taglib prefix=&quot;c&quot; uri=&quot;http://java.sun.com/jsp/jstl/core&quot; %&gt;</p>
</blockquote>
<h2 id="三-实际效果和原来还是一模一样的">三、实际效果和原来还是一模一样的</h2>
<figure data-type="image" tabindex="1"><img src="https://zydnc.gitee.io/post-images/1611968722793.png" alt="" loading="lazy"></figure>
<blockquote>
<p>原文作者：絷缘<br>
作者邮箱：zhiyuanworkemail@163.com<br>
原文地址：<a href="https://zhiyuandnc.github.io/AqFeWp4vE/">https://zhiyuandnc.github.io/AqFeWp4vE/</a><br>
版权声明：本文为博主原创文章，转载请注明原文链接作者信息</p>
</blockquote>

                </div>
            </article>
        </div>

        
            <div class="next-post">
                <div class="next gt-c-content-color-first">下一篇</div>
                <a href="https://zydnc.gitee.io/360Video/" class="post-title gt-a-link">
                    JavaWeb阶段练习：360影视数据采集
                </a>
            </div>
        

        

        

        

        <div class="site-footer gt-c-content-color-first">
    <div class="slogan gt-c-content-color-first">事实不以人的意志为转移</div>
    <div class="social-container">
        
            
                <a href="#" target="_blank">
                    <i class="fab fa-github gt-c-content-color-first"></i>
                </a>
            
        
            
                <a href="#" target="_blank">
                    <i class="fab fa-telegram gt-c-content-color-first"></i>
                </a>
            
        
            
                <a href="#" target="_blank">
                    <i class="fab fa-qq gt-c-content-color-first"></i>
                </a>
            
        
            
                <a href="#" target="_blank">
                    <i class="fab fa-bilibili gt-c-content-color-first"></i>
                </a>
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
    </div>
    <div class="footer-info">
        Copyright&ensp;&copy;&ensp;絷缘的博客<br/><a href="https://beian.miit.gov.cn/" target="_blank">晋ICP备20001723号-1</a>
    </div>
    <div>
        Theme by <a href="https://imhanjie.com/" target="_blank">imhanjie</a>, Powered by <a
                href="https://github.com/getgridea/gridea" target="_blank">Gridea | <a href="https://zydnc.gitee.io/atom.xml" target="_blank">RSS</a></a>
    </div>
</div>

<script>
  hljs.initHighlightingOnLoad()
</script>

    </div>
</div>
</body>
</html>
